﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System.Windows.Forms;
using WinAutomator.Library;

namespace WinAutomator.Plugin.Files.ReadDirectory
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class ReadDirectoryViewModel : PluginViewModel
    {

        private ReadDirectoryProcess _model;

        /// <summary>
        /// Initializes a new instance of the ReadDirectoryViewModel class.
        /// </summary>
        public ReadDirectoryViewModel()
        {
            _model = new ReadDirectoryProcess();
            ConnectorOut = new WAConnectorViewModel(_model.VOut);
            ConnectorIn = new WAConnectorViewModel(_model.VIn);
            this.Top = 20;
            this.Left = 100;
            TestCommandPassParamRC = new RelayCommand(() => TestCommandPassParam2());
        }


        public WAConnectorViewModel ConnectorIn { get; set; }
        public WAConnectorViewModel ConnectorOut { get; set; }

        public override IProcess Model
        {
            get { return _model; }
        }

        public RelayCommand TestCommandPassParamRC
        {
            get;
            private set;
        }

        private void TestCommandPassParam2()
        {
            var dialog = new FolderBrowserDialog();
            System.Windows.Forms.DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK)
                Directory = dialog.SelectedPath;
            
        }

        /// <summary>
        /// The <see cref="Directory" /> property's name.
        /// </summary>
        public const string DirectoryPropertyName = "Directory";

        private string _directory = "";

        /// <summary>
        /// Sets and gets the Directory property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public string Directory
        {
            get
            {
                return _model.Directory;
            }

            set
            {
                if (_directory == value)
                {
                    return;
                }

                //RaisePropertyChanging(DirectoryPropertyName);
                _model.Directory = value;
                RaisePropertyChanged(DirectoryPropertyName);
            }
        }
    }
}